package cd.cdyb.sms.config;

import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;

import java.util.ArrayList;

public class DefaultClientDetailsServiceImpl implements ClientDetailsService {

    private static final BaseClientDetails CLIENT_USER;

    static {
        ArrayList<String> scopes = new ArrayList<>();
        scopes.add("all");

        ArrayList<String> grantTypes = new ArrayList<>();
        grantTypes.add("password");

        CLIENT_USER = new BaseClientDetails();
        CLIENT_USER.setClientId("helpCenter");//客户端id
        CLIENT_USER.setClientSecret("e10adc3949ba59abbe56e057f20f883e"); //客户端密码
        CLIENT_USER.setScope(scopes);
        CLIENT_USER.setAuthorizedGrantTypes(grantTypes);//授权类型
        CLIENT_USER.setAccessTokenValiditySeconds(60 * 60 * 24 * 7);//7天
//        CLIENT_USER.setAccessTokenValiditySeconds(20);//7天

    }

    @Override
    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        BaseClientDetails clientUser = CLIENT_USER;
        return clientUser;
    }
}
